-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug where fvh fragments could be loaded from wrong doc #65641
Conversation
@@ -160,8 +160,13 @@ public HighlightField highlight(FieldHighlightContext fieldContext) throws IOExc | |||
} | |||
cache.fvh.setPhraseLimit(field.fieldOptions().phraseLimit()); | |||
|
|||
String[] fragments; | |||
// If the fragments builder requires document _source, pass it the source lookup from the hit context. | |||
if (entry.fragmentsBuilder instanceof SourceBasedFragmentsBuilder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hacky but felt like the best way to fix this right now. FragmentsBuilder
is an external (Lucene) interface and there's not a good way to pass in _source to its methods like getFields
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we replace the cached FragmentsBuilder with a Function<SourceLookup, FragmentsBuilder>
and then call that with the new SourceLookup for each hit? The FragmentsBuilders themselves don't seem to do any significant processing on construction so I don't think there would be a performance penalty for rebuilding them each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that should work! I'd like to check I understand the context. We have these cached entries not because fragment builders are expensive to build, but to avoid rebuilding the FieldQuery
which looks more complex?
a4b4af4
to
ab7abb6
Compare
Pinging @elastic/es-search (Team:Search) |
Thanks @romseygeek for the suggestion, I tried out the new approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @jtibshirani!
…5641) This PR fixes a regression where fvh fragments could be loaded from the wrong document _source. Some `FragmentsBuilder` implementations contain a `SourceLookup` to load from _source. The lookup should be positioned to load from the current hit document. However, since `FragmentsBuilder` are cached and shared across hits, the lookup is never updated to load from the new documents. This means we accidentally load _source from a different document. The regression was introduced in elastic#60179, which started storing `SourceLookup` on `FragmentsBuilder`. Fixes elastic#65533.
…5641) This PR fixes a regression where fvh fragments could be loaded from the wrong document _source. Some `FragmentsBuilder` implementations contain a `SourceLookup` to load from _source. The lookup should be positioned to load from the current hit document. However, since `FragmentsBuilder` are cached and shared across hits, the lookup is never updated to load from the new documents. This means we accidentally load _source from a different document. The regression was introduced in elastic#60179, which started storing `SourceLookup` on `FragmentsBuilder`. Fixes elastic#65533.
This PR fixes a regression where fvh fragments could be loaded from the wrong
document _source.
Some
FragmentsBuilder
implementations contain aSourceLookup
to load from_source. The lookup should be positioned to load from the current hit document.
However, since
FragmentsBuilder
are cached and shared across hits, the lookupis never updated to load from the new documents. This means we accidentally
load _source from a different document.
The regression was introduced in #60179, which started storing
SourceLookup
on
FragmentsBuilder
.Fixes #65533.